//
//  DCFCommonUtils.h
//  DCF
//
//  Created by 吴文拼 on 2017/12/26.
//  Copyright © 2017年 吴文拼. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef enum {
    typeOnlyYear,
    typeOnlyMoth,
    typeOnlyDay,
    typeOnlyHour,
    typeOnlyMin,
    typeYearMonthDay,
    typeYearMonthDayHourMin,
    typeYearMonthDayHourMinSec,
    typeMonthAndDay,
    typeMonthDayHourMin,
    typeHourAndMin
}FormatterType;

@interface DCFCommonUtils : NSObject

#pragma mark --Common通用
//延时执行函数
+ (void)delay:(NSTimeInterval)time cmp:(void (^)(void))cmp;

#pragma mark --NSString字符串相关
//判断空(支持类型NSString、NSArray、NSDictionary、NSSet)
+ (BOOL)isEmpty:(id)obj;
//字符串修整（去掉首尾空格）
+ (NSString *)trim:(NSString *)string;
//计算字符串的size，是str的boundingRect方法的封装。
+ (CGSize)string:(NSString *)string size:(CGSize)size fontSize:(CGFloat)fontSize;
//正则表达式匹配，返回NSRange数组(此方法不记录匹配到的子分组，如需要子分组，需要重新写一个方法)
+ (NSArray *)stringRegularMatch:(NSString *)origin pattern:(NSString *)pattern;
//根据字典获取json字符串
+(NSString *)convertToJsonData:(NSDictionary *)dict;

//打开外部链接
+ (void)openUrlWithUrlStr:(NSString *)urlStr completeBlock:(void (^)(BOOL success))complete;
//跳转到设置界面
+ (void)openSystemSettingWithcompleteBlock:(void (^)(BOOL success))complete;

//跳转到AppStore
+ (void)goToAppStore;

//时间戳之间的天数
+ (NSInteger)getDaysFromTs:(NSInteger)tsStart withTsEnd:(NSInteger)tsEnd;
//时间戳转化为时间
+ (NSString *)stringFromTimeSP:(long long)_timesp;
+ (NSString *)stringFromTimeSP:(long long)_timesp formatter:(FormatterType)formatterType;
//时间转化为时间戳
+ (NSString *)getTimeStampFromString:(NSString *)dateStr withFormat:(NSString *)formatStr;
+ (NSString *)getTimestampFromDate:(NSDate *)date;

//计算两个日期之间的天数
+ (NSInteger)caculateDays:(NSDate *)startDate To:(NSDate *)endDate;

//根据string返回date
+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format;
//+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format;

//获取当前时间
+ (NSString *)getCurrentDate:(FormatterType)formatterType;
+ (NSString *)getCurrentDate:(FormatterType)formatterType addTimeInterval:(NSTimeInterval)timeInterval;

//计算高度  用这个宏方便点TextHeight
+ (float)heightWithFont:(UIFont *)font maxWidth:(float)maxWidth string:(NSString *)string;
//计算宽度  用这个宏方便点TextWidth
+ (float)widthWithFont:(UIFont *)font maxHeight:(float)maxHeight string:(NSString *)string;

//检查url
+ (NSString *)verifyUrl:(NSString *)url;

//获取string 包含string的range
+ (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string;

@end
